package com.zhoug.zmuidemo;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.zhoug.common.adapters.recycler.BaseRecyclerViewAdapter;
import com.zhoug.common.adapters.recycler.BaseViewHolder;
import com.zhoug.common.adapters.recycler.dividers.ListItemDecoration;
import com.zhoug.common.router.ZRouter;
import com.zhoug.zmuidemo.ui.AlphaViewActivity;
import com.zhoug.zmuidemo.ui.CanvasActivity;
import com.zhoug.zmuidemo.ui.ChooserActivity;
import com.zhoug.zmuidemo.ui.DialogActivity;
import com.zhoug.zmuidemo.ui.EmptyViewActivity;
import com.zhoug.zmuidemo.ui.LinePathActivity;
import com.zhoug.zmuidemo.ui.MapSdkActivity;
import com.zhoug.zmuidemo.ui.MarqueeActivity;
import com.zhoug.zmuidemo.ui.MenuActivity;
import com.zhoug.zmuidemo.ui.NavigationActivity;
import com.zhoug.zmuidemo.ui.PopupActivity;
import com.zhoug.zmuidemo.ui.RatingBarActivity;
import com.zhoug.zmuidemo.ui.RatioViewActivity;
import com.zhoug.zmuidemo.ui.RefreshActivity;
import com.zhoug.zmuidemo.ui.RoundViewActivity;
import com.zhoug.zmuidemo.ui.SearchViewActivity;
import com.zhoug.zmuidemo.ui.SideBarActivity;
import com.zhoug.zmuidemo.ui.StickyActivity;

import java.util.Arrays;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.OrientationHelper;
import androidx.recyclerview.widget.RecyclerView;

public class MainActivity extends AppCompatActivity {
    private RecyclerView mRecyclerView;

    private List<Component> mData= Arrays.asList(
            new Component("ZMUIDialog(窗口)", DialogActivity.class),
            new Component("AlphaView",AlphaViewActivity .class),
            new Component("roundView(圆形View)", RoundViewActivity.class),
            new Component("图片相交模式 ",CanvasActivity .class),
            new Component("ZMUIPopup", PopupActivity.class),
            new Component("ZMUIEmptyView(空View)", EmptyViewActivity.class),
            new Component("navigation(底部导航菜单)", NavigationActivity.class),
            new Component("marquee(跑马灯)", MarqueeActivity.class),
            new Component("ZMUILinePathView(手写签名) ", LinePathActivity.class),
            new Component("RatingBar ", RatingBarActivity.class),
            new Component("RatioView ", RatioViewActivity.class),
            new Component("SearchView ", SearchViewActivity.class),
            new Component("ZMUIStickyScrollView ",StickyActivity .class),
            new Component("ZMUIRefreshLayout ", RefreshActivity.class),
            new Component("Chooser ", ChooserActivity.class),
            new Component("MenuDialog",MenuActivity .class),
            new Component("MapSdkManager", MapSdkActivity.class),
            new Component("ZMUISideBar", SideBarActivity.class)
    );


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViews();
    }

    private void findViews() {
        mRecyclerView = findViewById(R.id.recyclerView);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.addItemDecoration(new ListItemDecoration(this, OrientationHelper.VERTICAL));
        Adapter adapter = new Adapter();
        adapter.setData(mData);
        mRecyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseRecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseRecyclerViewAdapter adapter, View view, int position) {
                Class cls = mData.get(position).cls;
                if(cls!=null){
                    ZRouter.navigation(MainActivity.this, cls  );
                }else{
                    Toast.makeText(getApplicationContext(), "没有配置class", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }


    private class Component {
        private String name;
        private Class cls;

        public Component(String name, Class cls) {
            this.name = name;
            this.cls = cls;
        }
    }

    private class Adapter extends BaseRecyclerViewAdapter<Component> {

        @Override
        public int getLayoutId(int viewType) {
            return R.layout.layout_text_item;
        }

        @Override
        public void onBindData(BaseViewHolder holder, Component data, int position, int viewType) {
            if (data != null) {
                holder.setText(R.id.text, data.name);
            }
        }
    }
}